package designpatterns.flyweight;

import java.util.HashMap;
import java.util.Map;

// 享元工厂角色
public class FlyweightFactory {
    private Map<String, Flyweight> flyweights = new HashMap<>();

    public Flyweight getFlyweight(String key) {
        Flyweight flyweight = flyweights.get(key);
        if(flyweight == null) {
            flyweight = new Flyweight1(key);
            flyweights.put(key, flyweight);
        }

        return flyweight;
    }
}
